package ATMAgain;

import ATM.MyJText;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ChangePwdFrame extends JFrame {
    ICodeService service = new CodeServiceImpl();
    private MyJText nowPwd = new ATM.MyJText("请输入旧密码",50,10,this);
    private MyJText newPwd = new ATM.MyJText("请输入新密码",50,90,this);
    private MyJText rePwd = new MyJText("确认新密码",50,130,this);

    public ChangePwdFrame(){
        this.setLayout(null);

        this.init();

        this.setSize(500,300);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
    }

    private void init(){
        MyButton pwdChange = new MyButton("改密码",350,200,this);

        pwdChange.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                changePwd();
            }
        });
    }

    private void changePwd(){
        String str = service.changePwd(nowPwd.getText(),newPwd.getText(),rePwd.getText());
        if (str!=null){
            JOptionPane.showMessageDialog(null,str);
        }else {
            ChangePwdFrame.this.dispose();
            new MainFrame();
        }
    }
}
